<?php
 session_start();
 date_default_timezone_set('PRC');
 include_once '../inc/conn.php';
 require '../inc/checkdate.php';
 ?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>oa系统</title>
<link rel="stylesheet" rev="stylesheet" href="../css/style.css" type="text/css" media="all" />


<script language="JavaScript" src ="../js/task.js" type="text/javascript">
</script>
<script language="JavaScript" src ="../js/select_date.js" type="text/javascript">
</script>
<style type="text/css">
<!--
.atten {font-size:12px;font-weight:normal;color:#F00;}
-->
</style>
</head>
<?php 
$tid=$_GET['id'];
 if(!empty($tid)){
 	
		 $query_str = "select * from task where id='$tid'";
		 $result = $oa->query($query_str);
		 $row = mysql_fetch_array($result);
		 	$task_title = $row['task_title'];
		 	$start_time = $row['start_time'];
		 	$stop_time  = $row['stop_time'];
		 	$performer  = $row['performer'];
		 	$content    = $row['content'];
		 	
 	
 ?>
<body class="ContentBody">
  <form action="" method="post"  name="fom" id="fom"   onSubmit="javascript:return check(this);">
<div class="MainDiv">
<table width="99%" border="0" cellpadding="0" cellspacing="0" class="CContent">
  <tr>
      <th class="tablestyle_title" >任务修改页面</th>
  </tr>
  <tr>
    <td class="CPanel">
		
		<table border="0" cellpadding="0" cellspacing="0" style="width:100%">
		<tr><td align="left">
		
		</td></tr>

		<TR>
			<TD width="100%">
				<fieldset style="height:100%;">
				<legend>修改任务</legend>
					  <table border="0" cellpadding="2" cellspacing="1" style="width:100%">
					 
					  <tr>
					    <td nowrap align="right" width="13%">任务标题:</td>
					    <td width="41%"><input name="task_title"  value="<?php echo $task_title; ?>" class="text" style="width:250px" type="text" size="40" />
				        <span class="red"> *</span></td>
					    <td align="right" width="19%"></td>
					    <td width="27%"></td>
					    </tr>
					  <tr>
					    <td nowrap align="right">计划开始时间:</td>
					    <td>
					    <input type="text"  name="start_time" value="<?php echo date('Y-m-d',$start_time); ?>" style="border:1px solid #999;" onclick="fPopCalendar(event,this,this)" onfocus="this.select()"  /> 
					    </td>
					    <td align="right">计划结束时间:</td>
					    <td>
					    <input type="text"  name="stop_time"  value="<?php echo date('Y-m-d',$stop_time) ;?>" style="border:1px solid #999;" onclick="fPopCalendar(event,this,this)" onfocus="this.select()"  /> 
					    </td>
					  </tr>
					   <tr>
					    <td nowrap align="right">任务执行人:</td>
					    <td>
					    <input type="text" name="performer" id="performer" value="<?php echo $performer;?>" style="width:154px" >
					    </td>
					    <td align="right">优先级:</td>
					    <td><select name="level" >
                      
                          <option selected="selected" value="1">暂不需要</option>
                          <option value="2">一般</option>
                          <option value="3">需要</option>
                          <option value="4">急</option>
                          <option value="5">很急</option>
                        </select></td>
					  </tr>
					  <tr>
					    <td nowrap align="right" height="120px">任务说明:</td>
					    <td colspan="3"><textarea id="textarea" name="content" rows="5" cols="80"><?php echo $content;?></textarea></td>
					    </tr>
					  </table>
			 <br />
				</fieldset>	</TD>
		  </TR>	
		</TABLE>
	 </td>
  </tr>
		<TR>
			<TD colspan="2" align="center" height="50px">
			<input type="submit" name="edit" value="修改" class="button" />　
			
			<input type="button" name="Submit2" value="返回" class="button" onclick="window.history.go(-1);"/></TD>
		</TR>
		</TABLE>
	 </td>
  </tr> 
  </table>

</div>
</form>
<?php
 
if (isset($_POST['edit'])){
	
	$task_title = addslashes(trim($_POST['task_title']));
	$t1 = trim(($_POST['start_time']));//开始时间取出
	$t2  = trim($_POST['stop_time']);//结束时间取出
	
	$performer  = addslashes(trim($_POST['performer']));
	$level      = addslashes(trim($_POST['level']));
	$content    = addslashes(trim($_POST['content']));
	$create_time= strtotime(date('Y-m-d H:i:s'));
	//$sender     = $_SESSION["username"];
	//echo  $task_title."  ".$start_time." ".$stop_time." ".$performer." ".$level." ".$content ;
	
	check_date($t1);
	check_date($t2);
	$start_time=strtotime($t1);
	$stop_time=strtotime($t2);
	$total=$stop_time-$start_time;
	if ($start_time>$stop_time)
	{
		echo "<script>alert('起始与终止的时间选择不正确');</script>";
	}
    
	else{	
			 			
	 $task_edit="update task set task_title='$task_title',create_time='$create_time',start_time='$start_time',stop_time='$stop_time',total_time='$total',performer='$performer',task_level='$level',content='$content' where id=".$tid;
	
	 
	if($oa->query($task_edit)){
	 					echo  "<script>alert('修改成功!'); window.location.href='listrenwu.php';</script>";
	 				}
	 
	
	
    }
  }
 }
?>

</body>
</html>
